package com.linuxgt.android.spapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.linuxgt.android.spapp.service.PreferencesService;

import java.util.Map;


public class MainActivity extends AppCompatActivity {

    private EditText nameText;
    private EditText ageText;
    private PreferencesService preferencesService;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        nameText = (EditText) findViewById(R.id.name);
        ageText = (EditText) findViewById(R.id.age);
        preferencesService = new PreferencesService(this);
        Map<String, String> params = preferencesService.getPreferences();
        nameText.setText(params.get("name"));
        ageText.setText(params.get("age"));
    }

    public void save(View v){
        String name = String.valueOf(nameText.getText());
        String age = String.valueOf(ageText.getText());
        preferencesService.save(name, Integer.valueOf(age));
        Toast.makeText(this, R.string.save_success, Toast.LENGTH_LONG).show();
    }
}
